package com.headfirst.dmp.report.tags

import org.apache.commons.lang.StringUtils
import org.apache.spark.sql.Row

/**
  * 打设备相关标签
  */
object Tags4DevicesTag extends TagsTrait {

  /**
    * 打标签（操作系统、设备类型、网络接入方式、运营商名称）
    *
    * @param args  传入数据为Row对象
    * @return
    */
  override def makeTags(args: Any*): Map[String, Int] = {

    //创建一个空Map，用于存储数据
    var map = Map[String, Int]()

    //将数据转换为Row对象
    val row: Row = args(0).asInstanceOf[Row]


    val os = row.getAs[Int]("client") //操作系统
    val phoneType = row.getAs[String]("device") //设备类型
    val ntm = row.getAs[String]("networkmannername") //网络接入方式
    val ispname = row.getAs[String]("ispname") //运营商名称


    os match {
      case 1 => map += ("D00010001" -> 1)
      case 2 => map += ("D00010002" -> 1)
      case 3 => map += ("D00010003" -> 1)
      case _ => map += ("D00010004" -> 1)
    }


    if (StringUtils.isNotBlank(phoneType)) {
      map += "DN" + phoneType -> 1
    }


    ntm.toUpperCase match {
      case "WIFI" => map += "D00020001" -> 1
      case "4G" => map += "D00020002" -> 1
      case "3G" => map += "D00020003" -> 1
      case "2G" => map += "D00020004" -> 1
      case _ => map += "D00020005" -> 1
    }


    ispname match {
      case "移动" => map += "D00030001" -> 1
      case "联通" => map += "D00030002" -> 1
      case "电信" => map += "D00030003" -> 1
      case _ => map += "D00030004" -> 1
    }



    val provinceName = row.getAs[String]("provincename")
    val cityname = row.getAs[String]("cityname")

    if(StringUtils.isNotBlank(provinceName)) map += ("ZP"+provinceName -> 1)
    if(StringUtils.isNotBlank(cityname)) map += ("ZP"+cityname -> 1)



    //返回值
    map


  }
}
